<template>
  <div class="container">
    <el-divider content-position="left">基本资料</el-divider>
    <el-form ref="form" :rules="rules" :model="singleData" label-width="100px">
      <el-form-item prop="usercode" label="用户名">
        <el-input v-model="singleData.usercode" disabled></el-input>
      </el-form-item>
      <el-form-item prop="username" label="姓名">
        <el-input v-model="singleData.username"></el-input>
      </el-form-item>
      <el-form-item prop="phone" label="手机号">
        <el-input v-model="singleData.phone"></el-input>
      </el-form-item>
      <el-form-item prop="sex" label="性别">
        <el-radio-group v-model="singleData.sex">
          <el-radio :label="1">男</el-radio>
          <el-radio :label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="生日" prop="birthday">
        <el-date-picker
          v-model="singleData.birthday"
          type="date"
          placeholder="选择生日"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="个性签名" prop="description">
        <el-input
          type="textarea"
          show-word-limit
          maxlength="50"
          v-model="singleData.description"
        ></el-input>
      </el-form-item>
      <div style="text-align: center">
        <el-button @click="submit">保存修改</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import editAndAdd from "../../../mixins/business/editAndAdd";

export default {
  name: "index",
  mixins: [editAndAdd],
  data() {
    return {
      singleData: {
        birthday: "",
        description: "",
        phone: "",
        sex: 0,
        usercode: "",
        userid: 0,
        username: ""
      },
      rules: {
        username: { required: true, message: "姓名不能为空!" }
      }
    };
  },
  created() {
    this.axios.get("/sys/user/getLoginUser").then(res => {
      this.singleData = res;
    });
  },
  methods: {
    submit() {
      this.axios
        .post("/sys/user/updateLoginUser", this.singleData)
        .then(() => this.$notify.success("修改成功!"))
        .catch(err => this.$notify.error(`修改失败,${err}!`));
    }
  }
};
</script>

<style scoped>
.el-form {
  width: 500px;
}
</style>
